#include "widget.h"
#include "ui_widget.h"
#include <QMessageBox>


int step = 0;
int errorCount = 0;

QString question[] =
{
    "老公的生日是什么时辰?",
    "老公的身高是?",
    "老公和易烊千玺谁帅?",
    "用最美的话语夸赞老公,在下面输入"
};

QString answer1[] =
{
    "A.子时",
    "B.丑时",
    "C.未时",
    "D.酉时"
};

QString answer2[] =
{
    "A.1.73m",
    "B.1.74m",
    "C.1.75m",
    "D.1.82m"
};
QString answer3[] =
{
    "A.老公帅!!",
    "B.老公比易烊千玺帅很多!!",
    "C.易烊千玺能和我老公比?",
    "D.以上都是"
};


QString position[] = {
    "第一个宝贝在大房间猫爬上去的天花板上面，快去找吧",
    "第二个宝贝在老公的白色匡威鞋子里面",
    "第三个宝贝在大房间厕所的洗手柜里面",
    "最后一个礼物在老公的裤裆里，去嗦两口"
};

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    connect(ui->pushButton,&QPushButton::clicked,this,&Widget::lastQuestion);

    dialog = new QDialog(this);//创建对话框对象
//    dialogNG = new QDialog(this);


    dialog->setWindowTitle("这你也能错？");
    dialog->resize(200,100);
//    dialogNG->resize(200,100);
    processOn();
}

Widget::~Widget()
{
    delete ui;
    delete dialog;
}

void Widget::Correct()
{
    QMessageBox::information(dialog, tr("正确"),
                                            tr(position[step].toStdString().c_str()), QMessageBox::Ok);
    step++;
    processOn();
    errorCount = 0;
}

void Widget::UnCorrect()
{
    dialog->setWindowTitle("这你也能错？");
}

void Widget::connect2Dialog(QPushButton *button)
{
//    connect(button,&QPushButton::clicked,dialog,&QDialog::open);
    connect(button,&QPushButton::clicked,this,&Widget::Correct);
}

void Widget::disconnect2Dialog(QPushButton *button)
{
    disconnect(button,0,0,0);
}

void Widget::processOn()
{
    switch (step)
    {
        case 0:
            connect2Dialog(ui->pushButton_A);
            ui->pushButton_A->setText(answer1[0]);
            ui->pushButton_B->setText(answer1[1]);
            ui->pushButton_C->setText(answer1[2]);
            ui->pushButton_D->setText(answer1[3]);
            ui->textBrowser->setText(question[0]);
            break;
        case 1:
            disconnect2Dialog(ui->pushButton_A);
            connect2Dialog(ui->pushButton_B);
            ui->pushButton_A->setText(answer2[0]);
            ui->pushButton_B->setText(answer2[1]);
            ui->pushButton_C->setText(answer2[2]);
            ui->pushButton_D->setText(answer2[3]);
            ui->textBrowser->setText(question[1]);
            break;
        case 2:
            disconnect2Dialog(ui->pushButton_B);
            connect2Dialog(ui->pushButton_D);
            ui->pushButton_A->setText(answer3[0]);
            ui->pushButton_B->setText(answer3[1]);
            ui->pushButton_C->setText(answer3[2]);
            ui->pushButton_D->setText(answer3[3]);
            ui->textBrowser->setText(question[2]);
            break;
        case 3:
            dialog->setWindowTitle("不够，继续说");
             if(errorCount == 2)
             {
                step++;
             }

            break;
        case 4:
            break;
        default:
            break;
    }
}

void Widget::lastQuestion()
{
    step--;
}
